package com.wesley.command;

/**
 * <h1>遥控器</h1>
 * <p>详述</p>
 *
 * @Date: 2021/8/31
 */
public class RemoteController {

    Command[] onCommand;

    Command[] offCommand;

    Command undoCommand;

    public RemoteController() {
        onCommand = new Command[5];
        offCommand = new Command[5];

        // 初始化五组命令
        for (int i = 0; i < 5; i++) {
            onCommand[i] = new NulCommand();
            offCommand[i] = new NulCommand();
        }
    }


    public void setCommand(int no, Command on, Command off) {
        onCommand[no] = on;
        offCommand[no] = off;
    }

    /**
     * <h1>按下ON开关</h1>
     * <p>详述</p>
     *
     * @param no 第几排按钮
     * @author wei.xin
     * @date 2021/8/31
     */
    public void touchOn(int no) {
        onCommand[no].execute();
        undoCommand = onCommand[no];
    }

    /**
     * <h1>按下OFF开关</h1>
     * <p>详述</p>
     *
     * @param no 第几排按钮
     * @author wei.xin
     * @date 2021/8/31
     */
    public void touchOff(int no) {
        offCommand[no].execute();
        undoCommand = offCommand[no];
    }

    /**
     * <h1>撤销</h1>
     * <p>详述</p>
     * @author wei.xin
     * @date 2021/8/31
     */
    public void cancel() {
        undoCommand.cancel();
    }
}
